#################################
macro(init_enum_directories_files)
    set(ALL_SUB "")
    set(sub_result "")
    set(filelist "")
endmacro()

# 递归遍历目录文件
macro(enum_directories_files result root_dir)
    set(ALL_SUB "")
    file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*)
    foreach(sub ${ALL_SUB})
        if (IS_DIRECTORY ${root_dir}/${sub})
            set(sub_result "")
            enum_directories_files(sub_result ${root_dir}/${sub})
            LIST(APPEND ${filelist} ${sub_result})
        else()
            if (${sub} MATCHES ".h" OR ${sub} MATCHES ".c" OR ${sub} MATCHES ".cpp" OR ${sub} MATCHES ".mm")
                LIST(APPEND filelist ${root_dir}/${sub})
            endif ()
        endif()
    endforeach()
    set(${result} ${filelist})
endmacro()

macro(enum_directories_sources result root_dir)
    init_enum_directories_files()
    enum_directories_files(${result} ${root_dir})
endmacro()

# 根据配置移出指定的文件
MACRO(EXCLUDE_FILES src_files rescure exclude_dir)
    FILE(${rescure} excludefiles  ${exclude_dir})
    FOREACH(excludefile ${excludefiles})
        LIST(REMOVE_ITEM ${src_files} ${excludefile})
    ENDFOREACH(excludefile)
ENDMACRO(EXCLUDE_FILES)

# 从 SRC_DIR 目录种搜索并生成 ts 和 qm 文件
function(generate_translations CUSTOM_TARGET TS_DIR TS_FILES SRC_DIR)
    set(UPADTE_TS_TARGET_NAME ${CUSTOM_TARGET}_ts)
    set(UPADTE_QM_TARGET_NAME ${CUSTOM_TARGET}_qm)

    add_custom_target(${UPADTE_TS_TARGET_NAME}
        COMMAND Qt4::lupdate -recursive ${SRC_DIR} -ts ${TS_FILES}
        # COMMAND ${Qt5_LUPDATE_EXECUTABLE} -recursive ${SRC_DIR} -ts ${TS_FILES}
        WORKING_DIRECTORY ${TS_DIR})

    add_custom_target(${UPADTE_QM_TARGET_NAME}
        COMMAND Qt4::lrelease ${TS_FILES} 
        # COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS_FILES}
        WORKING_DIRECTORY ${TS_DIR})

    add_dependencies(${UPADTE_QM_TARGET_NAME} ${UPADTE_TS_TARGET_NAME} )
    add_dependencies(${CUSTOM_TARGET} ${UPADTE_QM_TARGET_NAME})
endfunction()